package com.eddie.jdbc.service.impl;

import com.eddie.jdbc.dao.impl.BaseDaoImpl;
import com.eddie.jdbc.entity.AccountEntity;
import com.eddie.jdbc.entity.PetStoreEntity;
import com.eddie.jdbc.service.PetStoreService;
import com.eddie.jdbc.vo.AccountVo;
import com.eddie.jdbc.vo.PetStoreVo;
import com.eddie.jdbc.vo.params.FindPetStoreParams;
import lombok.SneakyThrows;
import org.springframework.beans.BeanUtils;

import java.lang.reflect.Field;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * @author Eddie
 */
public class PetStoreServiceImpl extends BaseDaoImpl<PetStoreEntity> implements PetStoreService {

    @SneakyThrows
    @Override
    public PetStoreVo findByLoginUserAndPassword(FindPetStoreParams params) {
        String sql = "select *from %s where login_name=? AND password = ?".formatted(simpleName);
        PreparedStatement ps = conn.prepareStatement(sql);
        ps.setObject(1, params.getLoginName());
        ps.setObject(2, params.getPassword());
        ResultSet rs = ps.executeQuery();
        if (rs.next()) {
            PetStoreEntity petStore = new PetStoreEntity();
            getFilelds(rs, petStore);
            PetStoreVo petStoreVo = new PetStoreVo();
            BeanUtils.copyProperties(petStore, petStoreVo);
            return petStoreVo;
        }
        return null;
    }
}